package com.scommunity.uniapp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scommunity.common.ResponseResult;
import com.scommunity.domain.Notice;
import com.scommunity.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice")
public class UNoticeController {

    @Autowired
    private INoticeService noticeService;

    @GetMapping("/list")
    public ResponseResult list(){
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("notice_time");
        List<Notice> noticeList = noticeService.list(queryWrapper);
        return ResponseResult.success(noticeList);
    }

    @GetMapping("/getbyid")
    public ResponseResult getById(Long noticeId){
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        Notice notice = noticeService.getOne(queryWrapper.eq("notice_id", noticeId));
        return ResponseResult.success(notice);
    }
}
